/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.startup.musicstore.app.factory;

import com.startup.musicstore.model.Album;
import com.startup.musicstore.model.AlbumCategory;
import com.startup.musicstore.model.ArtistInformation;
import com.startup.musicstore.model.Contact;
import com.startup.musicstore.model.CreditCard;
import com.startup.musicstore.model.Customer;
import com.startup.musicstore.model.CustomerAddress;
import com.startup.musicstore.model.CustomerInvoice;
import com.startup.musicstore.model.Demographic;
import com.startup.musicstore.model.MarketingInformation;
import com.startup.musicstore.model.Orders;
import com.startup.musicstore.model.OrderItem;
import com.startup.musicstore.model.Review;
import com.startup.musicstore.model.SampleClip;
import com.startup.musicstore.model.Track;
import com.startup.musicstore.model.Name;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import org.joda.time.DateTime;

/**
 *
 * @author boniface
 */
public class AppFactory {

    // Create a Credit card with Name, balance, expiry date and credit Number 
    public static CreditCard getCreditCard(Map<String, String> details, BigDecimal balance, Date expiryDate) {
        CreditCard creditCard = new CreditCard();
        creditCard.setCreditNumber(details.get("number"));
        creditCard.setNameOnCreditCard(details.get("name"));
        creditCard.setBalance(balance);
        creditCard.setExpiryDate(expiryDate);
        return creditCard;
    }

    public static CustomerAddress getCustomerAddress(String streetAddress, String postalAddress) {
        CustomerAddress address = new CustomerAddress();
        address.setPostalAddress(postalAddress);
        address.setStreetAddress(streetAddress);
        return address;
    }

    public static Customer getCustomer(Map<String, String> values, Date dateOfBirth, List<CreditCard> cards) {
        Customer customer = new Customer();
        Name name = new Name();
        name.setFirstName(values.get("firstName"));
        name.setLastName(values.get("lastName"));
        Contact contact = new Contact();
        contact.setCellNumber(values.get("cellNumber"));
        contact.setPhoneNumber(values.get("phoneNumber"));
        Demographic demographic = new Demographic();
        demographic.setDateOfBirth(dateOfBirth);
        demographic.setGender(values.get("gender"));
        demographic.setRace(values.get("race"));
        customer.setContact(contact);
        customer.setDemographic(demographic);
        customer.setName(name);
        customer.setCustomerNumber(values.get("customerNumber"));
        customer.setCreditCards(cards);
        return customer;
    }

    public static OrderItem getOrderItem(int quantity, Album album) {

        OrderItem orderItem = new OrderItem();
        orderItem.setQuantity(quantity);
        orderItem.setAlbum(album);
        return orderItem;
    }
    
    public static Orders getOrder(Map<String, String> orderDetails, Customer customer) {        
        OrderItem orderItem = new OrderItem();
        orderItem.setQuantity(Integer.parseInt(orderDetails.get("quantity")));
        Album album = new Album();
        album.setId(new Long(orderDetails.get("albumID")));
        orderItem.setAlbum(album);
        List<OrderItem> orderItems = new ArrayList<OrderItem>();
        orderItems.add(orderItem);
        
        Orders order = new Orders();
        order.setCustomer(customer);
        order.setOrderDate(new Date());
        order.setOrderNumber(Integer.parseInt(orderDetails.get("orderNumber")));
        order.setOrderItems(orderItems);        
        
        return order;
    }
    
    public static CustomerInvoice getCustomerInvoice(Map<String, String> values) {       
        CustomerInvoice customerInvoice = new CustomerInvoice();
        customerInvoice.setInvoiceDate(new Date());
        customerInvoice.setInvoiceStatus(values.get("invoiceStatus"));
        Orders orders = new Orders();
        orders.setId(new Long(values.get("orderID")));
        customerInvoice.setOrder(orders);
        customerInvoice.setOrderAmount(new BigDecimal(values.get("orderAmount")));
        
        return customerInvoice;
    }

    public static AlbumCategory getAlbumCategory(String categoryName) {
        AlbumCategory albumCategory = new AlbumCategory();
        albumCategory.setCategoryName(categoryName);
        return albumCategory;
    }

    public static Track getTrack(int number, String title, String url) {
        SampleClip sampleClip = new SampleClip();
        sampleClip.setSampleUrl(url);
        Track track = new Track();
        track.setSampleClip(sampleClip);
        track.setTrackNumber(number);
        track.setTrackTitle(title);
        return track;
    }

    public static Album getAlbum(Map<String, String> albumDetails, List<Track> tracks, BigDecimal unitPrice) {

        Review review = new Review();
        review.setDescription(albumDetails.get("description"));

        ArtistInformation artistInformation = new ArtistInformation();
        artistInformation.setFirstName(albumDetails.get("firstName"));
        artistInformation.setLastName(albumDetails.get("lastName"));

        MarketingInformation marketingInformation = new MarketingInformation();
        marketingInformation.setStatusOfMarketingInformation(albumDetails.get("statusOfInformation"));

        marketingInformation.setArtistInformation(artistInformation);
        marketingInformation.setReview(review);

        Album album = new Album();
        album.setAlbumTitle(albumDetails.get("albumTitle"));
        album.setTracks(tracks);
        album.setUnitPrice(unitPrice);
        album.setmarketingInformation(marketingInformation);

        return album;
    }
    
    public static MarketingInformation getMarketingInformation(Map<String, String> details, Album album) {

        Review review = new Review();
        review.setDescription(details.get("description"));
        review.setRating(Integer.parseInt(details.get("rating")));

        ArtistInformation artistInformation = new ArtistInformation();
        artistInformation.setFirstName(details.get("firstName"));
        artistInformation.setLastName(details.get("lastName"));

        MarketingInformation marketingInformation = new MarketingInformation();
        marketingInformation.setStatusOfMarketingInformation(details.get("statusOfInformation"));

        marketingInformation.setArtistInformation(artistInformation);
        marketingInformation.setReview(review);
        marketingInformation.setAlbum(album);

        album.setmarketingInformation(marketingInformation);
        

        return marketingInformation;
    }
}
